Method and device for student training networks with teacher networks

ABSTRACT

A method and device for training a neural network are disclosed. The method comprises: selecting, by a training device, a teacher network performing the same functions of a student network; and iteratively training the student network and obtaining a target network, through aligning distributions of features between a first middle layer and a second middle layer corresponding to the same training sample data, so as to transfer knowledge of features of a middle layer of the teacher network to the student network.

CROSS-REFERENCES TO RELATED APPLICATIONS

The present application claims the priority from Chinese Patent Application No. 201710454691.6, filed with the Chinese Patent Office on Jun. 15, 2017 and entitled “METHOD AND DEVICE FOR TRAINING NEURAL NETWORK”, which is hereby incorporated by reference in its entirety.

FIELD

The present application relates to the computer vision field, and particularly to a method and a device for training a neural network.

BACKGROUND

In recent years, deep neural networks have achieved great success in various applications in computer vision, such as image classification, object detection, semantic segmentation and so on. However, models of deep neural network are hardly deployed in device with low power consumption and low computation ability for real-time computation (such as embedded device, integrated device, and so on), as these the models usually contain a large number of model parameters, require large computational resource and cause slow inference speed.

In the light of the issues described above, a lot of methods for accelerating deep neural networks have been proposed recently, such as network pruning, network weight quantization, network knowledge distillation and so on.

Although methods like network pruning and network quantization, except neuron pruning, can effectively decrease the number of parameters included in neural networks, they are not able to fully exploit modern GPU and deep learning frameworks; and their accelerations need specific hardware or implementations. Comparatively, knowledge distillation, which uses the extra information provided by teacher networks (featuring a large amount of network parameters, high performance and low-speed computation) to train student networks (featuring a small amount of network parameters, poor performance and high-speed computation) directly, can practically accelerate deep neural networks with existing frameworks. Therefore, knowledge distillation is a more commonly used method for acceleration of neutral networks nowadays.

At present, there are three main methods of knowledge distillation, which are “Knowledge Distill” (KD) proposed by Hinton et al. in Distilling the Knowledge in a Neural Network in 2014, “FitNets” proposed by Romero et al. in Fitnets: Hints for Thin Deep Nets in 2015, and “Attention Transfer” (AT) put forward by Sergey et al. in Paying More Attention to Attention: Improving the Performance of Convolutional Neural Networks via Attention Transfer in 2016.

To refer the teacher network to T and the student network to S, we can formulate the objective function of student network in KD as Equation (1):

$\begin{matrix} {\mathcal{L}_{KD} = {{\mathcal{H}\left( {y_{true},p_{S}} \right)} + {\lambda\;{\mathcal{H}\left( {{{softmax}\left( \frac{l_{T}}{\tau} \right)},{{softmax}\left( \frac{l_{S}}{\tau} \right)}} \right)}}}} & {{Equation}\mspace{14mu}(1)} \end{matrix}$

In Equation (1),

(⋅) represents the cross-entropy loss function, y_(true) represents the training label, p_(S)=softmax(l_(S)) refers the classification probability of the student network S, l_(T) and l_(S) refers to the output value of network T and S before softmax (known as logits) respectively, τ is a preset value (called temperature), and λ refers to the weight of transfer loss.

As shown in the second item of Equation (1), the basic idea of KD is to distill knowledge from a large teacher model into a small one by learning the class distribution provided by the teacher via softened softmax.

Different from KD, in order to learn from the intermediate representations of teacher network, FitNet makes the student mimic the full feature maps of the teacher. The objective function of student network is formulated as equation (2) below:

_(FitNet)=

(y _(true) ,p _(S))+λ∥F _(T)−

(F _(S))∥₂ ²  Equation (2)

In Equation (2), F_(T)∈

^(C) ^(T) ^(×HW) and F_(S)∈

^(C) ^(S) ^(×HW) refers to the feature map of a certain layer of teacher network and student network respectively; C_(T) and C_(S) refers to the number of channels of F_(T) and F_(S) respectively; H and W refers the height and the width of a feature map respectively; generally, the heights and widths of the feature maps of F_(T) and F_(S) are the same; if the heights and widths of the feature maps of F_(T) and F_(S) do not match, they should be processed to be the same by some simple difference functions or algorithms;

(⋅) refers to a convolution with a 1*1 kernel; S represents the number of channels of feature maps of F_(S), T represents the number of channels of feature maps of F_(T), and

(⋅) is used to reconcile the number of channels of feature map of F_(T) and

(F_(S)).

By aligning the features of middle layers of teacher network and student network, FitNet transfers the specific knowledge from the teacher network into the student network, and then improve the performance of the student network.

Similar to FitNet in principle, AT can improve the performance of student network by transferring the knowledge regarding the attention map of teacher network to the student network. The objective function of student network is defined by Equation (3) below:

_(AT)=

(y _(true) ,p _(S))+∥

(F _(T))−

(F _(S))∥₂ ²  Equation (3)

In equation (3),

(⋅) refers to a normalized projection function of attention map. Among all its definitions, the simplest definition of

(⋅) is found in equation (4):

$\begin{matrix} {{\mathcal{A}(F)} = \frac{\sum\limits_{i = 1}^{C}{f^{k \cdot}}}{{{\sum\limits_{i = 1}^{C}{f^{k \cdot}}}}_{2}}} & {{Equation}\mspace{14mu}(4)} \end{matrix}$

In Equation (4), f^(k⋅)∈

^(HW) refers to the vectorized feature map of the k-th channel of F.

Notes on Terminology:

Teacher network: a high-performance neural network used for providing more accurate supervision information to student network in the process of knowledge transfer.

Student Network: a poor-performance single neural network with fast computation speed, which can be deployed in actual application scenes with stricter real-time requirements; it is of smaller computational cost and fewer model parameters, compared to teacher network.

BRIEF SUMMARY

In an aspect, embodiments of the present application provides a method for training a neural network, the method including:

selecting, by a training device, a teacher network performing the same functions of a student network; and,

iteratively training the student network and obtaining a target network, through aligning distributions of features between a first middle layer and a second middle layer corresponding to the same training sample data, so as to transfer knowledge of features of a middle layer of the teacher network to the student network; wherein, the features of the first middle layer refer to feature maps output from a first specific network layer of the teacher network after the training sample data are provided to the teacher network, and the features of the second middle layer refer to feature maps output from a second specific network layer of the student network after the training sample data are provided to the student network.

In another aspect, embodiments of the present application further provide a device for training a neural network, the device including:

a selecting element, configured to select a teacher network performing the same functions of a student network; and

a training element, configured to iteratively train the student network and obtain a target network through aligning distributions of features of a first middle layer and a second middle layer corresponding to the same training sample data, so as to transfer knowledge of features of a middle layer of the teacher network into the student network; wherein, the features of the first middle layer refer to feature maps output from a first specific network layer of the teacher network after the training sample data are provided to the teacher network, and the features of the second middle layer refer to feature maps output from a second specific network layer of the student network after the training sample data are provided to the student network.

In another aspect, embodiments of the present application further provide a device for training a neural network, the device including: a processor and at least one memory, the at least one memory storing at least one machine executable instruction, which is executed by the processor to:

select a teacher network performing the same functions of a student network; and,

iteratively train the student network and obtain a target network, through aligning distributions of features between a first middle layer and a second middle layer corresponding to the same training sample data, so as to transfer knowledge of features of a middle layer of the teacher network to the student network; wherein, the features of the first middle layer refer to feature maps output from a first specific network layer of the teacher network after the training sample data are provided to the teacher network, and the features of the second middle layer refer to feature maps output from a second specific network layer of the student network after the training sample data are provided to the student network.

BRIEF DESCRIPTION OF THE DRAWINGS

The accompanying drawings are used to provide the further understanding of the present application and constitute a part of the specification, and serve to explain the present application together with the embodiments of the present application but not limit the present application.

FIG. 1 is a flow chart illustrating a method for training a neural network in embodiments of the present application;

FIG. 2 is flow chart illustrating iteratively training a student network and obtaining a target network in embodiments of the present application;

FIG. 3 is a structure schematic diagram of a device for training a neural network in embodiments of the present application;

FIG. 4 is a structure schematic diagram of a training element in embodiments of the present application; and

FIG. 5 is another structure schematic diagram of a device for training a neural network in embodiments of the present application.

DETAILED DESCRIPTION OF THE EMBODIMENTS

In order to make those of ordinary skill in the art better able to understand the technical solution in the present application, the technical solution in the embodiments of the present application will be described clearly and completely below in combination with the accompanying drawings. The described embodiments are just a part of the embodiments of the present application but not all the embodiments. Based upon the embodiments of the present application, all of other embodiments obtained by those of ordinary skill in the art without creative work should pertain to the protection scope of the present application.

There are a couple of technical defects in the prior art: KD could only be applied in classification tasks with softmax layers and could not be applied in regression tasks; and even when performing a classification task, KD often fail to provide sufficient knowledge to student network if there are only a small number of classes. FitNet is so strict about directly aligning features of middle layers, that it could not be effectively combined with other methods to train and obtain high-performance student networks. Student networks trained and obtained through AT often perform poorly. Therefore, the student networks trained through the existing knowledge transfer methods cannot reconcile broad application range and accuracy.

As for the neural network training scheme provided by the embodiments of the present application, on one aspect, it can train and obtain student networks with a broader application range through aligning features of middle layers of teacher networks with those of student networks, and can adopt both classification models and regression models; in another aspect, it can work with other methods to further enhance the performance and the accuracy of student networks, since its constraints on aligning the distribution of features of middle layers between teacher networks and student networks are less strict than that of directly aligning all the features of middle layers, namely the methods of the prior art.

Embodiment One

As shown in FIG. 1 , a flow chart of a method for training a neural network provided by embodiments of the current application is illustrated, where the method includes:

Step 101: selecting, by a training device, a teacher network performing the same functions of a student network.

The functions include such as image classification, object detection, semantic segmentation and so on. The teacher network is characterized by high performance and high accuracy; but, compared to the student network, it has some obvious disadvantages such as complex structure, a large number of parameters and weights and low computation speed. The student network is characterized by fast computation speed, average or poor performance, and simple network structure. The high-performance teacher network with the same functions of the student network could be selected from a set of preset neural network models.

Step 102: iteratively training the student network and obtaining a target network, through aligning distributions of features between a first middle layer and a second middle layer corresponding to the same training sample data, so as to transfer knowledge of features of a middle layer of the teacher network to the student network.

Where, the features of the first middle layer refer to feature maps output from a first specific network layer of the teacher network after the training sample data are provided to the teacher network, and the features of the second middle layer refer to feature maps output from a second specific network layer of the student network after the training sample data are provided to the student network.

In the embodiments of the present application, the feature maps output from the first specific network layer of the teacher network is generally referred to the features of the first middle layer, after the training sample data are provided to the teacher network; the feature maps output from the second specific network layer of the student network is generally referred to the features of the second middle layer, after the training sample data are provided to the student network.

In some embodiments of the present application, the first specific network layer is a middle network layer or the last network layer of the teacher network.

In some embodiments of the present application, the second specific network layer is a middle network layer or the last network layer of the student network.

In some embodiments, the step 102 described above could be implemented as the method illustrated in FIG. 2 , including:

Step 102A: building an objective function of the student network, where the objective function includes a task specific loss function and a distance loss function, and the distance loss function is a function used to measure the distance between the distributions of the features of the first middle layer and the distributions of the features of the second middle layer corresponding to the same training sample data.

In embodiments of the present application, the form of the task specific loss function is related to the task of the student network. For example, when the task of the student network is a classification task, the form of the task specific loss function is a cross-entropy loss function; and when the task of the student network is a regression task, the form of the task specific loss function is a distance loss function.

Step 102B: iteratively training the student network by using the training sample data.

Step 102C: obtaining the target network, when the iteration number of training reaches a threshold or the objective function satisfies the preset convergence conditions.

As for step 102B in embodiments of the present application, the training sample data used in each iteration of training is different. Step 102B described above could be implemented as below:

iteratively training the student network for multiple times by taking the steps described below (Hereinafter referred to as the current iteration of training, where the training sample data used in the current iteration of training is referred to as the training sample data in the current iteration, and the current iteration of training includes step A, step B and step C):

step A: feeding the training sample data in the current iteration into the teacher network and the student network respectively, and obtaining the features of the first middle layer and the second middle layer corresponding to the training sample data in the current iteration;

Step B: calculating the value of the objective function according to the training sample data in the current iteration and the corresponding features of the first middle layer and the second middle layer thereto, and adjusting the weights of the student network according to the value of the objective function; and,

Step C: continuing to the training of next iteration based on the weight adjusted student network.

In some embodiments, as for the aforementioned step B, adjusting the weights of the student network according to the value of the objective function could be implemented as: adjusting the weights of the student network according to the value of the objective function with a gradient descent optimization function.

In a specific embodiment, the objective function of the student network could be expressed as equation (5) below:

=

(y _(true) ,p _(S))+λ

_(MMD) ₂ (F _(T) ,F _(S))  equation (5)

In equation (5),

(y_(true), p_(S)) refers to the cross-entropy loss function,

_(MMD) ₂ (F_(T), F_(S)) refers to the distance loss function, λ refers to the weight of distance loss function, F_(T) refers to the feature map (i.e. the features of the first middle layer) output from the first specific network layer of the teacher network given the training sample data, F_(S) refers to the feature map (i.e. the features of the second middle layer) output from the second specific network layer of the student network given the training sample data, y_(true) refers to the ground-truth labels of the training sample data, and p_(S) refers to the output classification probability of the student network.

F_(S)∈

^(C) ^(S) ^(×HW), and F_(T)∈

^(C) ^(T) ^(×HW), where C_(T) refers to the number of channels of F_(T), C_(S) refers to the number of channels of F_(S), and H and W represents respectively the height and the width of F_(T) and F_(S). The sizes of F_(T) and F_(S) are the same in the embodiments of the present application.

In some embodiments, between the step A and the step B, the method further includes: judging whether the heights of F_(T) and F_(S) are the same or not, if they are different then taking the one with a higher value as the aforementioned H; judging whether the widths of F_(T) and F_(S) are the same or not, and if they are different then taking the one with a higher value as the aforementioned W; and adjusting the sizes of F_(T) and F_(S) to be H and W by using a preset interpolating function.

In some embodiments, the

_(MMD) ₂ (F_(T), F_(S)) in the objective function of the embodiments could be formulated in equation (6) below:

$\begin{matrix} {{\frac{1}{C_{T}^{2}}{\sum\limits_{i = 1}^{C_{T}}{\sum\limits_{i^{\prime} = 1}^{C_{T}}{k\left( {\frac{f_{T}^{i \cdot}}{{f_{T}^{i \cdot}}_{2}},\frac{f_{T}^{i^{\prime} \cdot}}{{f_{T}^{i^{\prime} \cdot}}_{2}}} \right)}}}} + {\frac{1}{C_{S}^{2}}{\sum\limits_{j = 1}^{C_{S}}{\sum\limits_{j^{\prime} = 1}^{C_{S}}{k\left( {\frac{f_{S}^{j \cdot}}{{f_{S}^{j \cdot}}_{2}},\frac{f_{S}^{j^{\prime} \cdot}}{{f_{S}^{j^{\prime} \cdot}}_{2}}} \right)}}}} - {\frac{2}{C_{T}C_{S}}{\sum\limits_{i = 1}^{C_{T}}{\sum\limits_{j = 1}^{C_{S}}{k\left( {\frac{f_{T}^{i \cdot}}{{f_{T}^{i \cdot}}_{2}},\frac{f_{S}^{j \cdot}}{{f_{S}^{j \cdot}}_{2}}} \right)}}}}} & {{Equation}\mspace{14mu}(6)} \end{matrix}$

In equation (6), k(⋅,⋅) refers to a preset kernel function, C_(T) refers to the number of channels of F_(T), C_(S) refers to the number of channels of F_(S), f_(T) ^(i⋅) represents the vectorized feature map of the i-th channel of F_(T), f_(T) ^(i′⋅) represents the vectorized feature map of the i′-th channel of F_(T), f_(S) ^(j⋅) refers to the vectorized feature map of the j-th channel of F_(S), and f_(S) ^(J′⋅) refers to the vectorized feature map of the j′-th channel of F_(S).

In some embodiments, k(⋅,⋅) could be a preset linear kernel function, a preset polynomial kernel function, a preset Gaussian kernel function, or a combination of multiple preset Gaussian kernel functions, which is not strictly limited in the present application, and could be set flexibly by those of ordinary skill in the art according to actual requirements.

A specific embodiment is as follow: k(⋅,⋅) is a linear kernel function expressed as equation (7) below; or k(⋅,⋅) is a polynomial kernel function expressed as equation (8) below; or k(⋅,⋅) is a Gaussian kernel function expressed as equation (9) below.

$\begin{matrix} {{k\left( {x,y} \right)} = {x^{T}y}} & {{equation}\mspace{14mu}(7)} \\ {{k\left( {x,y} \right)} = \left( {{x^{T}y} + c} \right)^{d}} & {{equation}\mspace{14mu}(8)} \\ {{k\left( {x,y} \right)} = {\exp\left( {- \frac{{{x - y}}_{2}^{2}}{2\;\sigma}} \right)}} & {{equation}\mspace{14mu}(9)} \end{matrix}$

Embodiment Two

Based upon the same concept of the method for training a neural network provided above, some embodiments of the present application further provide a device for training a neural network. The structure of the device is shown in FIG. 3 , which includes:

A selecting element 31, configured to select a teacher network performing the same functions of a student network.

The functions include such as image classification, object detection, semantic segmentation and so on. The teacher network is characterized by high performance and high accuracy; but, compared to the student network, it has some obvious disadvantages such as complex structure, a large number of parameters and weights, and low computation speed. The student network is characterized by fast computation speed, average or poor performance, and simple network structure. The high-performance teacher network with the same functions of the student network could be selected from a set of preset neural network models.

In the embodiments of the application, the feature map output from the first specific network layer of the teacher network is generally referred to the features of the first middle layer, after the training sample data are provided to the teacher network; the feature map output from the second specific network layer of the student network is generally referred to the features of the second middle layer, after the training sample data are provided to the student network.

A training element 32, configured to iteratively train the student network and obtain a target network, through aligning distributions of features of a first middle layer and a second middle layer corresponding to the same training sample data, so as to transfer knowledge of features of a middle layer of the teacher network into the student network; wherein, the features of the first middle layer refer to feature maps output from a first specific network layer of the teacher network after the training sample data are provided to the teacher network, and the features of the second middle layer refer to feature maps output from a second specific network layer of the student network after the training sample data are provided to the student network.

In some embodiments of the application, the first specific network layer is a middle network layer or the last network layer of the teacher network; and/or, the second specific network layer is a middle network layer or the last network layer of the student network.

In some embodiments of the application, FIG. 4 illustrates the structure of the training element 32. The training element 32 includes a building module 321, a training module 322 and a determining module 323, where:

the building module 321 is configured to build an objective function of the student network, where the objective function includes a task specific loss function and a distance loss function, and the distance loss function is a function used to measure the distance between the distributions of the features of the first middle layer and the distributions of the features of the second middle layer corresponding to the same training sample data.

In some embodiments of the application, the form of the task specific loss function is related to the task of the student network. For example, when the task of the student network is a classification task, the form of the task specific loss function is a cross-entropy loss function; and when the task of the student network is a regression task, the form of the task specific loss function is a distance loss function.

The training module 322 is configured to iteratively train the student network using the training sample data.

The determining module 323 is configure to obtain the target network, when the iteration number of training reaches a threshold or the objective function satisfies the preset convergence conditions.

In some embodiments of the application, the training module 322 is specifically configured to:

iteratively train the student network for multiple times by taking the steps described below (Hereinafter referred to as the current iteration of training, the training sample data used in the current iteration of training is referred to as the training sample data in the current iteration, and the current iteration of training includes step A, step B and step C):

step A: feeding the training sample data in the current iteration into the teacher network and the student network respectively, and obtaining the features of the first middle layer and the second middle layer corresponding to the training sample data in the current iteration;

Step B: calculating the value of the objective function according to the training sample data in the current iteration and the corresponding features of the first middle layer and the second middle layer thereto, and adjusting the weights of the student network according to the value of the objective function; and,

Step C: continuing to the training of next iteration based on the weight adjusted student network.

In some embodiments, as for the aforementioned step B, adjusting the weights of the student network according to the value of the objective function could be implemented as: adjusting the weights of the student network according to the value of the objective function with a gradient descent optimization function.

In some embodiments, the objective function built by the building module 321 could be expressed as the equation (5) described above, the distance loss function could be expressed as the equation (6) described above, and a detailed description thereof will be omitted here.

Embodiment Three

Based upon the same concept of the method for training a neural network provided above, some embodiments of the present application further provide a device for training a neural network, the structure of the device is illustrated in FIG. 5 , which including: a processor 51 and at least one memory 52, the at least one memory storing at least one machine executable instruction, which is executed by the processor to:

select a teacher network performing the same functions of a student network; and,

iteratively train the student network and obtain a target network, through aligning distributions of features between a first middle layer and a second middle layer corresponding to the same training sample data, so as to transfer knowledge of features of a middle layer of the teacher network to the student network; wherein, the features of the first middle layer refer to feature maps output from a first specific network layer of the teacher network after the training sample data are provided to the teacher network, and the features of the second middle layer refer to feature maps output from a second specific network layer of the student network after the training sample data are provided to the student network.

In some embodiments, the processor 51 executes the at least one machine executable instruction to iteratively train the student network and obtain a target network, through aligning distributions of features between a first middle layer and a second middle layer corresponding to the same training sample data, the at least one machine executable instruction being executed by the processor to:

build an objective function of the student network, where the objective function includes a task specific loss function and a distance loss function, and the distance loss function is a function used to measure the distance between the distributions of the features of the first middle layer and the distributions of the features of the second middle layer corresponding to the same training sample data; iteratively train the student network by using the training sample data; obtain the target network, when the iteration number of training reaches a threshold or the objective function satisfies the preset convergence conditions.

In some embodiments, the processor 51 executes the at least one machine executable instruction to iteratively train the student network by using the training sample data, the at least one machine executable instruction being executed by the processor to:

iteratively train the student network over multiple iterations by: feeding the training sample data in a current iteration into the teacher network and the student network respectively, and obtain the features of the first middle layer and the second middle layer corresponding to the training sample data in the current iteration; calculate the value of the objective function according to the training sample data in the current iteration and the corresponding features of the first middle layer and the second middle layer thereto, and adjust the weights of the student network according to the value of the objective function; and continue the training with a next iteration based on the weight adjusted student network.

In some embodiments, the processor 51 executes the at least one machine executable instruction to adjust the weights of the student network according to the value of the objective function, the at least one machine executable instruction being executed by the processor to: adjust the weights of the student network according to the value of the objective function with a gradient descent optimization function.

In some embodiments, the objective function could be expressed as the equation (5) described above, the distance loss function could be expressed as the equation (6) described above, and a detailed description thereof will be omitted here.

In some embodiments, the first specific network layer is a middle network layer or the last network layer of the teacher network; and/or, the second specific network layer is a middle network layer or the last network layer of the student layer.

In the neural network training scheme provided by the embodiments of the application, in one aspect, the embodiments can train and obtain student networks with a broader application range through aligning features of middle layers of teacher networks with those of student networks, and can adopt both classification models and regression models; in another aspect, it can work with other methods to further enhance the performance and the accuracy of student networks, since its constraints on aligning the distribution of features of middle layers between teacher networks and student networks are less strict than that of directly aligning all the features of middle layers, namely the methods of the prior art.

It should be understood by those of ordinary skill in the art that the embodiments of the present application can provide methods, devices, systems, and computer program products. Thus, the present application can take the form of hardware embodiments alone, application software embodiments alone, or embodiments combining the application software and hardware aspects. Also the present application can take the form of computer program products implemented on one or more computer usable storage mediums (including but not limited to magnetic disk memories, CD-ROMs, optical memories and the like) containing computer usable program codes therein.

The present application is described by reference to the flow charts and/or the box diagrams of the methods, the devices (systems) and the computer program products according to the embodiments of the present application. It should be understood that each process and/or box in the flow charts and/or the box diagrams, and a combination of processes and/or blocks in the flow charts and/or the box diagrams can be implemented by the computer program instructions. These computer program instructions can be provided to a general-purpose computer, a dedicated computer, an embedded processor, or a processor of another programmable data processing device to produce a machine, so that an apparatus for implementing the functions specified in one or more processes of the flow charts and/or one or more blocks of the box diagrams is produced by the instructions executed by the computer or the processor of another programmable data processing device.

These computer program instructions can also be stored in a computer readable memory which is capable of guiding the computer or another programmable data processing device to operate in a particular way, so that the instructions stored in the computer readable memory produce a manufacture including the instruction apparatus which implements the functions specified in one or more processes of the flow charts and/or one or more blocks of the box diagrams.

These computer program instructions can also be loaded onto the computer or another programmable data processing device, so that a series of operation steps are performed on the computer or another programmable device to produce the computer-implemented processing. Thus the instructions executed on the computer or another programmable device provide steps for implementing the functions specified in one or more processes of the flow charts and/or one or more blocks of the box diagrams.

Although the preferred embodiments of the present application have been described, those of ordinary skill in the art can make additional alterations and modifications to these embodiments once they learn about the basic creative concepts. Thus, the attached claims are intended to be interpreted to include the preferred embodiments as well as all the alterations and modifications falling within the scope of the present application.

It will be appreciated that those of ordinary skill in the art can make various modifications and variations to the present application without departing from the spirit and scope of the present application. Thus, the present application is also intended to encompass these modifications and variations therein as long as these modifications and variations to the present application come into the scope of the claims of the present application and their equivalents. 

What is claimed is:
 1. A method for training a neural network, the method comprising: selecting, by a training device, a teacher network performing the same functions of a student network; iteratively training the student network and obtaining a target network, through aligning distributions of features between a first middle layer and a second middle layer corresponding to the same training sample data, so as to transfer knowledge of features of a middle layer of the teacher network to the student network; wherein, the features of the first middle layer refer to a feature map F_(T) output from a first specific network layer of the teacher network after the training sample data are provided to the teacher network, and the features of the second middle layer refer to a feature map F_(S) output from a second specific network layer of the student network after the training sample data are provided to the student network, wherein iteratively training the student network and obtaining the target network, comprises: building an objective function of the student network, wherein the objective function comprises:

=

(y _(true) ,p _(S))+λ

_(MMD) ₂ (F _(T) ,F _(S)) wherein,

(y_(true), p_(S)) refers to the cross-entropy loss function,

_(MMD) ₂ (F_(T), F_(S)) refers to the distance loss function, λ refers to the weight of the distance loss function, F_(T) refers to the feature map (i.e. the features of the first middle layer) output from the first specific network layer of the teacher network given the training sample data, F_(S) refers to the feature map (i.e. the features of the second middle layer) output from the second specific network layer of the student network given the training sample data, y_(true) refers to the ground-truth labels of the training sample data, and p_(S) refers to the output classification probability of the student network, F_(S)∈

^(C) ^(S) ^(×HW), F_(T)∈

^(C) ^(T) ^(×HW), C_(T) refers to a number of channels of F_(T), C_(S) refers to a number of channels of F_(S), H is a larger one of heights of F_(T) and F_(S), W is a larger one of widths of F_(T) and F_(S), the method further comprising: interpolating F_(T) and F_(S) according to H and W.
 2. The method according to claim 1, wherein iteratively training the student network and obtaining a target network, through aligning distributions of features between a first middle layer and a second middle layer corresponding to the same training sample data, comprises: building an objective function of the student network, where the objective function includes a task specific loss function and a distance loss function, and the distance loss function is a function used to measure the distance between the distributions of the features of the first middle layer and the distributions of the features of the second middle layer corresponding to the same training sample data; iteratively training the student network by using the training sample data; and, obtaining the target network, when the iteration number of training reaches a threshold or the objective function satisfies the preset convergence conditions.
 3. The method according to claim 2, wherein iteratively training the student network by using the training sample data, comprises: iteratively training the student network for multiple times by taking the steps described below: feeding the training sample data in the current iteration into the teacher network and the student network respectively, and obtaining the features of the first middle layer and the second middle layer corresponding to the training sample data in the current iteration; calculating the value of the objective function according to the training sample data in the current iteration and the corresponding features of the first middle layer and the second middle layer thereto, and adjusting the weights of the student network according to the value of the objective function; and, continuing to the training of next iteration based on the weight adjusted student network.
 4. The method according to claim 3, wherein adjusting the weights of the student network according to the value of the objective function, comprises: adjusting the weights of the student network according to the value of the objective function with a gradient descent optimization function.
 5. The method according to claim 1, wherein

_(MMD) ₂ (F_(T), F_(S)) in the objective function comprises: ${\frac{1}{C_{T}^{2}}{\sum\limits_{i = 1}^{C_{T}}{\sum\limits_{i^{\prime} = 1}^{C_{T}}{k\left( {\frac{f_{T}^{i \cdot}}{{f_{T}^{i \cdot}}_{2}},\frac{f_{T}^{i^{\prime} \cdot}}{{f_{T}^{i^{\prime} \cdot}}_{2}}} \right)}}}} + {\frac{1}{C_{S}^{2}}{\sum\limits_{j = 1}^{C_{S}}{\sum\limits_{j^{\prime} = 1}^{C_{S}}{k\left( {\frac{f_{S}^{j \cdot}}{{f_{S}^{j \cdot}}_{2}},\frac{f_{S}^{j^{\prime} \cdot}}{{f_{S}^{j^{\prime} \cdot}}_{2}}} \right)}}}} - {\frac{1}{C_{T}C_{S}}{\sum\limits_{i = 1}^{C_{T}}{\sum\limits_{j = 1}^{C_{S}}{k\left( {\frac{f_{T}^{i \cdot}}{{f_{T}^{i \cdot}}_{2}},\frac{f_{S}^{j \cdot}}{{f_{S}^{j \cdot}}_{2}}} \right)}}}}$ wherein, k(⋅,⋅) refers to a preset kernel function, C_(T) refers to the number of channels of F_(T), C_(S) refers to the number of channels of F_(S), f_(T) ^(1⋅) represents the vectorized feature map of the i-th channel of F_(T), f_(T) ^(1′⋅) represents the vectorized feature map of the i′-th channel of F_(T), f_(S) ^(j⋅) refers to the vectorized feature map of the j-th channel of F_(S), and f_(S) ^(j′⋅) refers to the vectorized feature map of the j′-th channel of F_(S).
 6. The method according to claim 5, wherein k(⋅,⋅) is a preset linear kernel function, a preset polynomial kernel function, or a preset Gaussian kernel function.
 7. The method according to claim 1, wherein the first specific network layer is a middle network layer or the last network layer of the teacher layer; and the second specific network layer is a middle network layer or the last network layer of the student layer.
 8. A device for training a neural network, the device comprising: a selecting element, configured to select a teacher network performing the same functions of a student network; and, a training element, configured to iteratively train the student network and obtain a target network, through aligning distributions of features of a first middle layer and a second middle layer corresponding to the same training sample data, so as to transfer knowledge of features of a middle layer of the teacher network into the student network; wherein, the features of the first middle layer refer to a feature map F_(T) output from a first specific network layer of the teacher network after the training sample data are provided to the teacher network, and the features of the second middle layer refer to a feature map F_(S) output from a second specific network layer of the student network after the training sample data are provided to the student network, wherein the training element comprises: a building module configured to build an objective function of the student network wherein the objective function built by the building module comprises:

=

(y _(true) ,p _(S))+λ

_(MMD) ₂ (F _(T) ,F _(S)) wherein,

(y_(true), p_(S)) refers to the cross-entropy loss function,

_(MMD) ₂ (F_(T), F_(S)) refers to the distance loss function, λ refers to the weight of the distance loss function, F_(T) refers to the feature map (i.e. the features of the first middle layer) output from the first specific network layer of the teacher network given the training sample data, F_(S) refers to the feature map (i.e. the features of the second middle layer) output from the second specific network layer of the student network given the training sample data, y_(true) refers to the ground-truth labels of the training sample data, and p_(S) refers to the output classification probability of the student network, F_(S)∈

^(C) ^(S) ^(×HW), F_(T)∈

^(C) ^(T) ^(×HW), C_(T) refers to a number of channels of F_(T), C_(S) refers to a number of channels of F_(S), H is a larger one of heights of F_(T) and F_(S), W is a larger one of widths of F_(T) and F_(S), wherein the building module is further configured to: interpolate F_(T) and F_(S) according to H and W.
 9. The device according to claim 8, wherein the building module is further configured to build an objective function of the student network, where the objective function includes a task specific loss function and a distance loss function, and the distance loss function is a function used to measure the distance between the distributions of the features of the first middle layer and the distributions of the features of the second middle layer corresponding to the same training sample data, the training element further comprises: a training module, configured to iteratively train the student network using the training sample data; and, a determining module, configure to obtain the target network, when the iteration number of training reaches a threshold or the objective function satisfies the preset convergence conditions.
 10. The device according to claim 9, wherein the training module, configured to iteratively train the student network for multiple times, is configured to: feed the training sample data in the current iteration into the teacher network and the student network respectively, and obtain the features of the first middle layer and the second middle layer corresponding to the training sample data in the current iteration; calculate the value of the objective function according to the training sample data in the current iteration and the corresponding features of the first middle layer and the second middle layer thereto, and adjust the weights of the student network according to the value of the objective function; and, continue to the training of next iteration based on the weight adjusted student network.
 11. The device according to claim 10, wherein the training module, configured to adjust the weights of the student network according to the value of the objective function, is specifically configured to: adjust the weights of the student network according to the value of the objective function with a gradient descent optimization function.
 12. The device according to claim 8, wherein

_(MMD) ₂ (F_(T), F_(S)) in the objective function comprises: ${\frac{1}{C_{T}^{2}}{\sum\limits_{i = 1}^{C_{T}}{\sum\limits_{i^{\prime} = 1}^{C_{T}}{k\left( {\frac{f_{T}^{i \cdot}}{{f_{T}^{i \cdot}}_{2}},\frac{f_{T}^{i^{\prime} \cdot}}{{f_{T}^{i^{\prime} \cdot}}_{2}}} \right)}}}} + {\frac{1}{C_{S}^{2}}{\sum\limits_{j = 1}^{C_{S}}{\sum\limits_{j^{\prime} = 1}^{C_{S}}{k\left( {\frac{f_{S}^{j \cdot}}{{f_{S}^{j \cdot}}_{2}},\frac{f_{S}^{j^{\prime} \cdot}}{{f_{S}^{j^{\prime} \cdot}}_{2}}} \right)}}}} - {\frac{2}{C_{T}C_{S}}{\sum\limits_{i = 1}^{C_{T}}{\sum\limits_{j = 1}^{C_{S}}{k\left( {\frac{f_{T}^{i \cdot}}{{f_{T}^{i \cdot}}_{2}},\frac{f_{S}^{j \cdot}}{{f_{S}^{j \cdot}}_{2}}} \right)}}}}$ wherein, k(⋅,⋅) refers to a preset kernel function, C_(T) refers to the number of channels of F_(T), C_(S) refers to the number of channels of F_(S), f_(T) ^(i⋅) represents the vectorized feature map of the i-th channel of F_(T), f_(T) ^(i′⋅) represents the vectorized feature map of the i′-th channel of F_(T), f_(S) ^(j⋅) refers to the vectorized feature map of the j-th channel of F_(S), and f_(S) ^(j′⋅) refers to the vectorized feature map of the j′-th channel of F_(S).
 13. The device according to claim 12, wherein k(⋅,⋅) is a preset linear kernel function, a preset polynomial kernel function, or a preset Gaussian kernel function.
 14. The device according to claim 8, wherein the first specific network layer is a middle network layer or the last network layer of the teacher layer; and the second specific network layer is a middle network layer or the last network layer of the student layer.
 15. A device for training a neural network, the device comprising a processor and at least one memory, the at least one memory storing at least one machine executable instruction, which is executed by the processor to: select a teacher network performing the same functions of a student network; iteratively train the student network and obtain a target network, through aligning distributions of features between a first middle layer and a second middle layer corresponding to the same training sample data, so as to transfer knowledge of features of a middle layer of the teacher network to the student network; wherein, the features of the first middle layer refer to a feature map F_(T) output from a first specific network layer of the teacher network after the training sample data are provided to the teacher network, and the features of the second middle layer refer to a feature map F_(S) output from a second specific network layer of the student network after the training sample data are provided to the student network, wherein the processor executes the at least one machine executable instruction to iteratively train the student network and obtain the target network, the at least one machine executable instruction being executed by the processor to: build an objective function of the student network, wherein the objective function comprises:

=

(y _(true) ,p _(S))+λ

_(MMD) ₂ (F _(T) ,F _(S)) wherein,

(y_(true), p_(S)) refers to the cross-entropy loss function,

_(MMD) ₂ (F_(T), F_(S)) refers to the distance loss function, λ refers to the weight of the distance loss function, F_(T) refers to the feature map (i.e. the features of the first middle layer) output from the first specific network layer of the teacher network given the training sample data, F_(S) refers to the feature map (i.e. the features of the second middle layer) output from the second specific network layer of the student network given the training sample data, y_(true) refers to the ground-truth labels of the training sample data, and p_(S) refers to the output classification probability of the student network, F_(S)∈

^(C) ^(S) ^(×HW), F_(T)∈

^(C) ^(T) ^(×HW), C_(T) refers to a number of channels of F_(T), C_(S) refers to a number of channels of F_(S), H is a larger one of heights of F_(T) and F_(S), W is a larger one of widths of F_(T) and F_(S), and interpolate F_(T) and F_(S) according to H and W.
 16. The device according to claim 15, wherein the processor executes the at least one machine executable instruction to iteratively train the student network and obtain a target network, through aligning distributions of features between a first middle layer and a second middle layer corresponding to the same training sample data, the at least one machine executable instruction being executed by the processor to: build an objective function of the student network, where the objective function includes a task specific loss function and a distance loss function, and the distance loss function is a function used to measure the distance between the distributions of the features of the first middle layer and the distributions of the features of the second middle layer corresponding to the same training sample data; iteratively train the student network by using the training sample data; and obtain the target network, when the iteration number of training reaches a threshold or the objective function satisfies the preset convergence conditions.
 17. The device according to claim 16, wherein the processor executes the at least one machine executable instruction to iteratively train the student network using the training sample data, the at least one machine executable instruction being executed by the processor to: iteratively train the student network over multiple iterations by: feeding the training sample data in a current iteration into the teacher network and the student network respectively, and obtaining the features of the first middle layer and the second middle layer corresponding to the training sample data in the current iteration; calculating the value of the objective function according to the training sample data in the current iteration and the corresponding features of the first middle layer and the second middle layer thereto, and adjusting the weights of the student network according to the value of the objective function; and continuing the training for a next iteration based on the weight adjusted student network. 